package com.imdroid.udp.filetyperequest;

import java.net.DatagramPacket;

import com.imdroid.udp.FileTypes;
import com.imdroid.udp.IntegerTransfer;
import com.imdroid.udp.UDPServer;

public class ConnectProcessor implements Processor{

	@Override
	public void service(DatagramPacket packet, long msgId, int sender, int payLoadStartIdx) {
		byte[] data = new byte[18];
		data[1] = FileTypes.CONNECT;
		System.arraycopy(IntegerTransfer.longToByte(msgId), 0, data, 2, 8);
		System.arraycopy(IntegerTransfer.longToByte(System.currentTimeMillis()), 0, data, 10, 8);
		DatagramPacket p = new DatagramPacket(data, 18);
		p.setAddress(packet.getAddress());
		p.setPort(packet.getPort());
		UDPServer.sendPacket(p);
		System.out.println("Heart beating ... " + packet.getAddress() + "--" + packet.getPort());
	}

}
